import { ProFormDigit } from '@ant-design/pro-components';
import { type ProFormDigitProps } from '@ant-design/pro-form/lib/components/Digit';

const CommonFormDigit: React.FC<ProFormDigitProps> = ({ required, rules = [], ...props }) => {
  return (
    <ProFormDigit
      {...props}
      rules={
        rules.some((rule) => 'required' in rule)
          ? rules
          : [
              {
                required,
                message: `请输入${props.label}`,
              },
              ...rules,
            ]
      }
    />
  );
};

CommonFormDigit.defaultProps = { required: false, placeholder: '' };

export default CommonFormDigit;
